import Vue from 'vue'
import Element from 'element-ui'
import '../element-variables.scss'
import { Message, Alert, MessageBox } from "element-ui";

let {Image: {components: {ImageViewer}}} = Element;
if(ImageViewer) {
    Vue.component('elImageViewer', ImageViewer);
}

Message.error = (msg) => {
    Message({
        message: msg,
        type: 'error',
        showClose: true
    })
}
Message.success = (msg) => {
    Message({
        message: msg,
        type: 'success',
        showClose: true
    })
}
// console.log(Alert, "0000000")

Vue.use(Element);
var $alert = Vue.prototype.$alert;
Vue.prototype.$alert = (...reset) => {
    try {
        let h = window.g_instance.$createElement;
        let message = <div>{reset[0]}</div>;
        let title = '提示';
        let options = reset[2] || {};
        if(typeof reset[1] === 'string') {
            title = reset[1];
        }else if(reset[1] instanceof Object) {
            options = reset[1];
        }
        if(!Object.prototype.hasOwnProperty.call(options, 'type')) {
            options.type = 'warning';
        }
        return MessageBox({
            title: title,
            message: message,
            ...(options || {})
        }); 

    }catch(e) {
        console.error(e, "提示错误！");
        $alert(...reset);
    }
    
}
